import Vue from  'vue'
import App from './App.vue'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import router from './router'
import store from './store'
import axios from 'axios';   //引入axios
Vue.config.productionTip = false
Vue.prototype.$axios = axios;  //配置axios 的全局
import { Toast,Indicator,Swipe, SwipeItem,Loadmore,InfiniteScroll} from 'mint-ui';
//引入Toast
Vue.$toast = Vue.prototype.$toast = Toast;
Vue.component(Swipe.name, Swipe);
Vue.component(SwipeItem.name, SwipeItem);
Vue.component(Loadmore.name, Loadmore);
Vue.use(MintUI);
Vue.use(InfiniteScroll);
// import qs from 'qs';
// axios.defaults.baseURL = 'https://ele-interface.herokuapp.com/';

// 全局设置请求拦截与响应拦截,在调接口的时加载loaing ,接口响应后关闭loading
//设置请求拦截
axios.interceptors.request.use(
  config=> {
    // if (config.method == 'post') {
    //   config.data = qs.stringify(config.data);
    // }
     // 加载动画
    Indicator.open();
    return config;
  }, error=>{
    return Promise.reject(error)
  }
);

//设置响应拦截
axios.interceptors.response.use(
   config=>{
      Indicator.close();
      Toast('请求成功');
      return config;
   },
   error=>{
      Toast('请求失败');
       return  Promise.reject(error);
   }
);








new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
